<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>济宁消防车辆人员出入管理系统</title>
<link rel="stylesheet" href="themes/default/easyui.css" />
<link rel="stylesheet" href="themes/icon.css" />
<link rel="stylesheet" href="css/main.css" />
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.easyui.min.js"></script>
</head>
<body class="easyui-layout">
	<div id="content" data-options="region:'center'">
		<table id="car_dg">
		</table>
		<div id="car_toolbar">
			<a href="javascript:addCar();" class="easyui-linkbutton"
				data-options="iconCls:'icon-add',plain:true">新增</a>
		</div>
		<div id="car_menu" class="easyui-menu"
			data-options="onClick:carMenuHandler" style="width: 120px;">
			<div data-options="name:'add',iconCls:'icon-add'">新增</div>
			<div data-options="name:'edit',iconCls:'icon-edit'">修改</div>
			<div data-options="name:'remove',iconCls:'icon-remove'">删除</div>
		</div>

		<div id="car_win" style="padding: 15px 30px; text-align: right;"></div>

		<script type="text/javascript">
			var car;
			function init() {
				$('#car_dg').datagrid({
					url : 'car/list',
					method : 'get',
					idField : 'id',
					loadMsg : '数据正在加载中。。。',
					pagination : true,
					pageSize:30,
					fit : true,
					fitColumns : true,
					rownumbers : true,
					remoteSort:false,
					columns : [ [ {
						field : 'id',
						hidden : true
					}, {
						field : 'license',
						title : '车牌号',
						sortable: true,
						width : 1
					}, {
						field : 'cardNumber',
						title : '卡号',
						width : 1
					}, {
						field : 'organization',
						title : '所属机构',
						sortable: true,
						width : 2,
						align : 'center'
					}, {
						field : 'masterName',
						title : '车主',
						sortable: true,
						width : 2,
						align : 'center'
					}, {
						field : 'masterPhone',
						title : '车主手机号码',
						width : 2,
						align : 'center'
					} ] ],
					toolbar : '#car_toolbar',
					onRowContextMenu : function(e, rowIndex, rowData) {
						car = rowData;
						e.preventDefault();
						$("#car_menu").menu('show', {
							left : e.pageX,
							top : e.pageY
						});
					},
					onDblClickRow : function(rowIndex, rowData) {
						car = rowData;
						editCar(rowData.id);
					}
				}).datagrid('getPager').pagination({
					pageSize : 30,
					beforePageText : "第",
					afterPageText : "条",
					displayMsg : "第 {from} 到 {to} 条，共 {total} 条"
				});

			};

			function carMenuHandler(item) {
				switch (item.name) {
				case 'add':
					addCar();
					break;
				case 'remove':
					removeCar(car.id)
					break;
				case 'edit':
					editCar(car.id);
					break;
				}
			}

			function addCar() {
				$('#car_win').window({
					title : '新增车辆',
					width : 400,
					height : 300,
					modal : true,
					collapsible : false,
					minimizable : false,
					maximizable : false,
					resizable : false,
					href : 'car/add'
				});

			}
			function editCar(carId) {
				$('#car_win').window({
					title : '修改车辆',
					width : 400,
					height : 300,
					modal : true,
					collapsible : false,
					minimizable : false,
					maximizable : false,
					resizable : false,
					href : 'car/update/' + carId
				});
			}
			function removeCar(carId) {
				$.messager.confirm('确认', '您确认想要删除记录吗？', function(r) {
					if (r) {
						$.post('car/delete/' + carId,
								function(data) {
									if (data.success) {
										$('#car_dg').datagrid('reload');
										showMsg("操作成功。");
									} else {
										$.messager.alert('错误提示', data.message,
												'error');
									}
								});
					}
				});
			}

			function saveCar() {
				var form = $('#car_form').form('submit', {
					success : function(data) {
						data = $.parseJSON(data);
						if (data.success) {
							$('#car_dg').datagrid('reload');
							$('#car_win').window('close');
							showMsg("操作成功。");
						} else {
							$.messager.alert('错误提示', data.message, 'error');
						}
					}

				});

			}

			$(function() {
				init();
				
			});
		</script>
	</div>
</body>
</html>
